package com.huajx.core.beetl;

import java.util.Date;

import com.huajx.util.ObjectUtil;
import com.huajx.util.convert.Convert;
import com.huajx.util.date.DatePattern;
import com.huajx.util.date.DateUtil;
import org.beetl.core.Context;
import org.beetl.core.Function;

public class LongToDate implements Function {

	@Override
	public Object call(Object[] arg0, Context arg1) {
		if(ObjectUtil.isEmpty(arg0)){
			return "";
		}
		Long date = Convert.toLong(arg0[0], null);
		if(date == null){
			return "";
		}
		Date date1 = new Date(date);
		String format = DatePattern.NORM_DATETIME_PATTERN;
		
		if(arg0.length > 1){
			format = Convert.toStr(arg0[1], DatePattern.NORM_DATETIME_PATTERN);
		}
		
		return DateUtil.format(date1, format);
	}

}
